package com.gxuwz.check.action.teacher;

import com.alibaba.fastjson.JSONObject;
import com.gxuwz.check.base.BaseAction;
import com.gxuwz.check.model.dto.ClassDto;
import com.gxuwz.check.model.dto.CourseDto;
import com.gxuwz.check.model.dto.StudentDto;
import com.gxuwz.check.service.admin.IStudentService;
import com.gxuwz.check.service.teacher.ITeacherService;
import com.gxuwz.check.util.ResultJson;
import com.opensymphony.xwork2.ModelDriven;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;

public class TeacherAction extends BaseAction implements ModelDriven{
    @Override
    public Object getModel() {
        return null;
    }
    private int userId; //用户Id
    private int page;
    private int classId; //班级Id
    private int peopleNum; //抽查人数

    private String studentIdArray; //缺勤学生
    private int classIdSelect; //班级ID
    private int courseId;//课程ID
    private int userIdNow;//教师ID

    private int classIdCharts;
    @Autowired
    private ITeacherService teacherService;
    @Autowired
    private IStudentService studentService;
    /**
     * 获取教师所带的所有班级
     */
    public void classList(){

        List<ClassDto> list = teacherService.classList(userId);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        jsonObject.put("list",list);
        ResultJson.R(jsonObject);
    }

    /**
     * 查询老师所教课程
     * @return
     */
    public void findCourseByTeacherId(){
        System.out.println("userId "+userId);
        List<CourseDto> list = teacherService.findCourseByTeacherId(userId);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        jsonObject.put("list",list);
        ResultJson.R(jsonObject);
    }

    /**
     * 查询出学生列表（根据班级）
     */
    public void findStudentList(){
        if (peopleNum == 0){
            List<StudentDto> list = studentService.list(page,classId,peopleNum);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code",20000);
            jsonObject.put("list",list);
            ResultJson.R(jsonObject);
        }
        else {
            List<StudentDto> list = studentService.listRandom(classId,peopleNum);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code",20000);
            jsonObject.put("list",list);
            ResultJson.R(jsonObject);
        }

    }


    /**
     * 缺勤添加
     */
    public void submitChecks(){
        String[] array = studentIdArray.split(",");//前台传来的学生字符串转为数组（本来是传数组，没成功，暂时传字符串）
        teacherService.submitChecks(array,classIdSelect,courseId,userIdNow);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        jsonObject.put("info","保存成功");
        ResultJson.R(jsonObject);
    }

    /**
     * 班级学生缺勤前10可视化
     * @return
     */
    public void getAbsenceMaxTen(){
        Map<String,List> map = teacherService.getAbsenceMaxTen(classIdCharts);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        jsonObject.put("listAbsenceNum",map.get("listAbsenceNum"));
        jsonObject.put("listStuName",map.get("listStuName"));
        ResultJson.R(jsonObject);
    }




    public int getUserId() {
        return userId;
    }
    public void setUserId(int userId) {
        this.userId = userId;
    }
    public int getClassId() {
        return classId;
    }
    public void setClassId(int classId) {
        this.classId = classId;
    }
    public int getPage() {
        return page;
    }
    public void setPage(int page) {
        this.page = page;
    }
    public int getClassIdSelect() {
        return classIdSelect;
    }
    public void setClassIdSelect(int classIdSelect) {
        this.classIdSelect = classIdSelect;
    }
    public int getCourseId() {
        return courseId;
    }
    public void setCourseId(int courseId) {
        this.courseId = courseId;
    }
    public String getStudentIdArray() {
        return studentIdArray;
    }
    public void setStudentIdArray(String studentIdArray) {
        this.studentIdArray = studentIdArray;
    }
    public int getUserIdNow() {
        return userIdNow;
    }
    public void setUserIdNow(int userIdNow) {
        this.userIdNow = userIdNow;
    }
    public int getPeopleNum() {
        return peopleNum;
    }
    public void setPeopleNum(int peopleNum) {
        this.peopleNum = peopleNum;
    }

    public int getClassIdCharts() {
        return classIdCharts;
    }

    public void setClassIdCharts(int classIdCharts) {
        this.classIdCharts = classIdCharts;
    }
}
